import 'package:flutter/foundation.dart';
import 'package:yysk_app/env/env.dart';
import 'package:oktoast/oktoast.dart';
import 'package:universal_html/html.dart';
import 'package:url_launcher/url_launcher.dart';

void storeToken(dynamic token) {
  window.localStorage['token'] = token;
}

String getToken() {
  return window.localStorage['token'] ?? '';
}

void saveToLocalStorage(String key, String value) {
  window.localStorage[key] = value;
}

String getFromLocalStorage(String key) {
  return window.localStorage[key] ?? '';
}

//hash地址跳转
class HashUrl {
  static const String baseUrl =
      'https://taianexplorer.bsnbase.com/transaction-detail?data='; //hash地址
}

// ignore: camel_case_types 密钥key
class encryptkey {
  static const String baseUrl = r"G6v7a9rvt&^9t&aBLJA7"; //hash地址
}

//协议地址
// ignore: camel_case_types
class rulePages {
  static const String userRule =
      r"https://cdn-s3.sz-jh.com/agreement/%E7%94%A8%E6%88%B7%E5%8D%8F%E8%AE%AE.html"; //用户协议
  static const String privacyAgreement =
      r"https://cdn-s3.sz-jh.com/agreement/%E9%9A%90%E7%A7%81%E6%94%BF%E7%AD%96.html"; //隐私协议
  static const String Disclaimer =
      r"https://cdn-s3.sz-jh.com/agreement/%E5%85%8D%E8%B4%A3%E5%8D%8F%E8%AE%AE.html"; //免责声明
  static const String IpDaoDisclaimer = r"https://www.baidu.com"; //ipDao免责声明
  static const String DecompositionOfActivities =
      r"https://www.baidu.com"; //分解活动用户须知
}

// ignore: non_constant_identifier_names
void consoleLog(String String) {
  if (Env.envConfig.envName != 'prd') {
    if (kDebugMode) {
      print(String);
    }
  }
}

// 示例：在按钮点击时打开浏览器
void launchURL(String url) async {
  final Uri uri = Uri.parse(url);

  // 检查是否能处理该 URL 类型
  if (await canLaunchUrl(uri)) {
    await launchUrl(
      uri,
      mode: LaunchMode.externalApplication, // 强制使用外部浏览器
    );
  } else {
    // 处理无法打开的情况（可选）

    throw showToast('无法打开 $url');
  }
}
